<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        ul{
            list-style: none;
        }
        #box {
            width: 300px;
            height: 300px;
            border: 1px solid #000;
            margin-top: 30px;
        }
    </style>
</head>

<body>
    <h3>简易留言板</h3>
    <input type="text" id="txt">
    <input type="button" value="留言" id="btn">
    <div id="box">
        <ul id="uls"></ul>
    </div>
    <script>
            var txt = document.getElementById("txt");
            var btn = document.getElementById("btn");
            var uls = document.getElementById("uls");
            btn.onclick=function(){
                var oli=document.getElementsByTagName("li");
                var li=document.createElement("li");
                uls.appendChild(li);
                li.innerHTML=txt.value+"<a href='javascript:;'>删除</a>";
                txt.value="";
                var aa=document.getElementsByTagName("a");
                for(var i=0;i<aa.length;i++){
                    aa[i].onclick=function(){
                    alert(333);
                        uls.removeChild(this.parentNode);
                    }
                }
            }
        </script>
</body>

</html>